<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>每日基金</title>
		<link rel="shortcut icon" href="favicon.ico">
		<!-- <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script> -->
		<!-- <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.0/axios.min.js"></script> -->
		<!-- <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/echarts/3.8.0/echarts-en.common.min.js"></script> -->
		<!-- <script type="text/javascript" src="echarts.min.js"></script> -->
		<script src="https://cdn.bootcdn.net/ajax/libs/echarts/3.8.5/echarts.min.js"></script>
		<!-- <script src="https://cdn.bootcdn.net/ajax/libs/echarts/4.0.0/echarts.min.js"></script> -->
		<!-- <script src="https://cdn.bootcdn.net/ajax/libs/echarts/5.0.0/echarts.min.js"></script> -->
		</script>
		<script type="text/javascript">
			
		</script>
	</head>
	<body>
		
		<div id="chartmain" style="width:37.5rem; height: 25rem;"></div>
	</body>
	<script type="text/javascript">
		var code = this.getQueryString("code") || '000339';
		var head = document.head || document.getElementsByTagName('head')[0];
		var script = document.createElement('script');
		script.setAttribute("src", "https://fund.eastmoney.com/pingzhongdata/" + code + ".js?v=20160518155842");
		script.setAttribute("id", "data");
		head.appendChild(script);
		// https://www.jianshu.com/p/708c915fb905
		function getQueryString(name) {
			let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
			let r = window.location.search.substr(1).match(reg);
			if (r != null) {
				return decodeURIComponent(r[2]);
			};
			return null;
		}
		//https://www.cnblogs.com/Kathrine/p/13182353.html   ajax
		
		
		/**
		 * data
		 * Data_netWorthTrend 单位净值走势 Data_netWorthTrend    x: new Date(item.x).Format("yyyy-MM-dd");
		 * Data_ACWorthTrend 累计净值走势 Data_ACWorthTrend		x: new Date(item[0]).Format("yyyy-MM-dd");
		 * Data_grandTotal 累计收益率    Data_grandTotal[0].data   x :new Date(item[0]).Format("yyyy-MM-dd");
		 */
		document.getElementById("data").onload = function() {
			console.log("code: "+ code +";\nstockCodes:"+fS_name)
			
			var myChart = echarts.init(document.getElementById('chartmain'));
			option = {
			    title: {
			        text: fS_name
			    },
			    tooltip: {
			        trigger: 'axis'
			    },
				legend: {
					data: ['单位净值', '累计净值']
				},
				//边距
				grid: {
					left: '3%',
					right: '4%',
					bottom: '3%',
					containLabel: true
				},
			    xAxis: {
			        data: Data_ACWorthTrend.map(function (item) {
			            return new Date(item[0]).Format("yyyy-MM-dd");
			            // return item[0];
			        })
			    },
			    yAxis: {
					type: "value",
			        splitLine: {
			            show: false
			        }
			    },
			    toolbox: {
			        feature: {
			            saveAsImage: {}
			        }
			    },
				dataZoom: [{
					startValue: '2014-06-01'
				}, {
					type: 'inside'
				}],
			    series: [
					{
						name: '单位净值',
						type: 'line',
						data: Data_netWorthTrend.map(function (item) {
						    return item.y;
						})
					},
					{
					    name: '累计净值',
					    type: 'line',
					    data: Data_ACWorthTrend.map(function (item) {
					        return item[1];
					    })
					}
				]
			}
			myChart.setOption(option);
			
		}
		
		Date.prototype.Format = function (fmt) { //author: meizz
		    var o = {
		        "M+": this.getMonth() + 1, //月份 
		        "d+": this.getDate(), //日 
		        "h+": this.getHours(), //小时 
		        "m+": this.getMinutes(), //分 
		        "s+": this.getSeconds(), //秒 
		        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
		        "S": this.getMilliseconds() //毫秒 
		    };
		    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
		    for (var k in o)
		    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
		    return fmt;
		}    
	</script>
</html>
